//
//  LGSiJiPublicChosedTypeController.m
//  ligenyun
//
//  Created by Mac on 2018/3/24.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "LGSiJiCustomTypeViewController.h"
#import "LGSijiChosedTypeCollectionViewCell.h"
#import "LGSiJiPublicFinshViewController.h"
#import "LGSiJiPublicFinshViewController.h"
@interface LGSiJiCustomTypeViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property(nonatomic, strong) UICollectionView                     *collectionView;
@end

@implementation LGSiJiCustomTypeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"创建私人陵园";
    [self configSubView];
    // Do any additional setup after loading the view.
}

#pragma mark --subView
- (void)configSubView{
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 300)];
    header.backgroundColor = [UIColor whiteColor];

    UIView * view = [TMUtils headerViewWithTitle:@"选择纪念馆末模板"];
    view.top = 0;
    view.backgroundColor = TM_backgroundColor;
    [header addSubview:view];
    
    header.height = view.bottom;
    header.top = -header.height;
    
    __weak typeof(self) weakSelf =  self;
    STButton * nextButton = [TMUtils deflutNextButton];
    [nextButton setClicAction:^(UIButton *sender) {
        [weakSelf onSlectedNextButton];
    }];
    [self.view addSubview:nextButton];
    
    UICollectionViewFlowLayout * flow = [UICollectionViewFlowLayout new];
    flow.minimumLineSpacing = 0;
    flow.minimumInteritemSpacing = 0;
    flow.scrollDirection = UICollectionViewScrollDirectionVertical;
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, [TMUtils navgationBarBootom], UIScreenWidth, [TMUtils tabBarTop]-[TMUtils navgationBarBootom]) collectionViewLayout:flow];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.view addSubview:self.collectionView];
    [self.collectionView addSubview:header];
    self.collectionView.contentInset = UIEdgeInsetsMake(header.height, 0, 0, 0);
    self.automaticallyAdjustsScrollViewInsets = NO;
    if (IOS11 && [self.collectionView respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) {
        [self.collectionView setContentInsetAdjustmentBehavior:@(2)];
    }
    [self.collectionView registerClass:[LGSijiChosedTypeCollectionViewCell class] forCellWithReuseIdentifier:@"item"];
}
#pragma --mark UICollectionViewDataSource
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 20;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(SCREEN_WIDTH/2, [LGSijiChosedTypeCollectionViewCell  itemHeight]);
}
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    __weak typeof(self) weakSelf =  self;
    LGSijiChosedTypeCollectionViewCell * item =[collectionView dequeueReusableCellWithReuseIdentifier:@"item" forIndexPath:indexPath];
    [item.chosedButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedChosedButtonWithIdnexPath:indexPath];
    }];
    return item;
}
#pragma --mark UICollectionViewDelegate
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    [self.collectionView deselectItemAtIndexPath:indexPath animated:NO];
}
#pragma mark --Action Method
- (void)onSelctedChosedButtonWithIdnexPath:(NSIndexPath*)indexPath{
    
}
- (void)onSlectedNextButton{
    
    LGSiJiPublicFinshViewController * vc = [LGSiJiPublicFinshViewController new];
    vc.dataSouce = [self.dataSouce copy];
    [self.navigationController pushViewController:vc animated:YES];
}
@end

